# coding=utf-8

import concurrent.futures


# 假设的转换函数，实际使用时替换为真实转换逻辑
def convert(docx_path, pdf_path):
    # 模拟转换耗时
    import time
    time.sleep(1)
    print(f"转换 {docx_path} 到 {pdf_path} 完成")


# 示例文件路径列表
file_paths = [
    ('doc1.docx', 'doc1.pdf'),
    ('doc2.docx', 'doc2.pdf'),
    ('doc3.docx', 'doc3.pdf'),
    ('doc4.docx', 'doc4.pdf'),
]

# 使用线程池执行转换任务
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
    # 将转换任务提交给线程池
    futures = {executor.submit(convert, docx_path, pdf_path): (docx_path, pdf_path) for docx_path, pdf_path in
               file_paths}

    # 遍历已完成的Future对象
    for future in concurrent.futures.as_completed(futures):
        docx_path, pdf_path = futures[future]
        try:
            data = future.result()
        except Exception as exc:
            print(f"{docx_path} 文档转为pdf失败: {exc}")
